package com.hzit.order.controller;

import com.hzit.order.config.RabbitMqConfig;
import com.hzit.order.service.OrderService;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;


    @Autowired
    private AmqpTemplate amqpTemplate;

    @RequestMapping("/create/{name}")
    public String create(@PathVariable("name") String name){

        return orderService.createOrder( name);
    }

    @RequestMapping("/test/{name}")
    public void test(@PathVariable("name") String name){
        //存入消息到mq ，过期时间
        amqpTemplate.convertAndSend(RabbitMqConfig.BUSINESS_EXCHANGE_NAME,null,name);

    }

}
